/*
 * Copyright (c) 2012 Universidad Antonio de Nebrija.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Apache License v2.0
 * which accompanies this distribution, and is available at
 * http://www.apache.org/licenses/LICENSE-2.0.html
 * 
 * Contributors:
 *    Universidad Antonio de Nebrija - initial API, implementation and documentation
 */
package com.nebrija.riif.parser;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;

import org.antlr.runtime.tree.Tree;

import com.nebrija.riif.model.ChildComponentList;
import com.nebrija.riif.model.ChildComponentUnit;
import com.nebrija.riif.model.Component;
import com.nebrija.riif.model.Parameter;
import com.nebrija.riif.model.RootClass;
import com.nebrija.riif.model.saver.bufferedwriter.RIIFWriterFormatSaverFactory;

/**
 * Example of how to process RIIF elements
 * @author asanchep
 *
 */
public class Main  {

  public static void main(String[] args) throws IOException {

	  System.out.println(System.currentTimeMillis());
	String val = "C:/Temp/simple_sram.RIIF";
	String val2 = "C:/Temp/asanchep_cpu.RIIF";
	String val3 = "C:/Temp/cpu_board.RIIF";

	ASTRIIFLoader loader = new ASTRIIFLoader();
	Tree t = loader.loadRIIF(val);
	ASTRIIFConverter converter = new ASTRIIFConverter();
	RootClass r = RootClass.getInstance();
	converter.processAST(t,r);
	t = loader.loadRIIF(val2);
	converter.processAST(t,r);
	t = loader.loadRIIF(val3);
	converter.processAST(t,r);
	/*t = loader.loadRIIF(val4);
	converter.processAST(t,r);*/
	
	r.resolve(null);
	//r.clear(null);
	
	System.out.println(r.toString());
	
	/*Parameter p = new Parameter("PRUEBA");
	p.setValue(10);
	((ChildComponentUnit)((ChildComponentList)(((Component)r.getElement("SIMPLE_CPU_BOARD")).getChildComponent("MEMORY"))).getChild(2)).addParameter(p);
	RIIFWriterFormatSaverFactory factory =  
			new RIIFWriterFormatSaverFactory(new BufferedWriter(new OutputStreamWriter(System.out)));
	factory.getComponentWriter().save((Component)r.getElement("SIMPLE_CPU_BOARD"));*/
  }
}
